********************************************************************************
* This is one of the replication files for Attitudes Toward Voting-Rights      *
* requirements by Hultin Rosenberg and Wejryd								   *
*																			   *	
* It is to be run on the WIDE dataset, in which each RESPONDENT is one unit,   *
* and has two purposes:														   *
* 1: To reproduce all descriptive statistics regarding respondents, for the    *	
* 	article as well as for the supplementary information					   *
* 2: To reproduce the LONG dataset, in which each rated profile is one unit    *
********************************************************************************


****************
* Use-variable *
****************

generate use = 1
replace use = 0 if gc !="1" // gc being Qualtrics' indicator for "Good completer"

********************************************************************************
* 					1a. Background variables for the article				   *
********************************************************************************


sum age if use==1 

sum genderrespondent if use==1

tab educationrespondent if use==1

tab usbornrespondent if use==1

tab householdincome if use==1

********************************************************************************
* 					1b. Background variables for the SI*					   *
********************************************************************************

ssc install tabout

global backgroundvar "agegr genderrespondent educationrespondent usbornrespondent employment householdincome importanceofdemocracy"

gen agegr=.
replace agegr=4 if age>18
replace agegr=agegr-1 if age<65
replace agegr=agegr-1 if age<45
replace agegr=agegr-1 if age<25
tab agegr if use==1

foreach var of varlist $backgroundvar{
tabout `var' if use==1 using tabulations.tsv, cells(freq cell cum) append
}

* Median response time
destring Duration, replace
sum Duration if use==1, detail

********************************************************************************
* 					2. Reshaping wide to long 								   *
********************************************************************************

********************************************************************************	
* Preparation: Finding and indicating responses with two or more tasks that are*
* given conflicting solutions 												   *
********************************************************************************

forvalues task = 1/6 {
	gen conficttask`task' = 0
	replace conficttask`task' = 1 if (choicepair`task' == 1 & ratingprofile`task'1 < ratingprofile`task'2)
	replace conficttask`task' = 1 if (choicepair`task' == 2 & ratingprofile`task'1 > ratingprofile`task'2)
	}

gen numberofconflictingtasks = conficttask1 + conficttask2 + conficttask3 + conficttask4 + conficttask5 + conficttask6
tab numberofconflictingtasks

generate conflicter = 0
replace conflicter = 1 if numberofconflictingtasks !=0

*************
* Reshaping *
*************

reshape long ratingprofile citizenshipyesprofile usbornprofile canadabornprofile mexicobornprofile philippnesbornprofile somaliabornprofile lessthanhighprofile highschoolprofile collegeprofile bachelorsprofile mastersprofile gendermanprofile incometaxyesprofile us15profile us3profile ustouristprofile europe15profile europe3profile, i(ResponseId) j(profilenumber)

**************************************
* Generating values for long dataset *
**************************************

*Dichotomous variables *

* Whether profile was chosen

gen chosen = 0
forvalues pair = 1/6 {
	replace chosen = 1 if profilenumber == `pair'1 & choicepair`pair' == 1
	replace chosen = 1 if profilenumber == `pair'2 & choicepair`pair' == 2
}

*A variable indicating if franchise for the respective profile was embraced or rejected in the rating 
* For positive rating
gen allowyes = 0
replace allowyes = 1 if ratingprofile == 5
replace allowyes = 1 if ratingprofile == 6
replace allowyes = 1 if ratingprofile == 7
replace allowyes = . if ratingprofile == .

* For negative rating
generate allowno=0
replace allowno= 1 if ratingprofile==1
replace allowno= 1 if ratingprofile==2
replace allowno= 1 if ratingprofile==3
replace allowno =. if ratingprofile==.

* Residency
gen residentyesprofile = 0
replace residentyesprofile = 1 if us15profile == 1
replace residentyesprofile = 1 if us3profile == 1

* US born is used by using "usbornprofile"

***************************************************************
* Giving profiles categorical factor variables for attributes *
***************************************************************

gen profilecitizenship = 1
replace profilecitizenship = 2 if citizenshipyesprofile==1
label define Citizen 1 "Not US citizen" 2 "US citizen"
label values profilecitizenship Citizen

gen profileborn = 1
replace profileborn = 2 if canadabornprofile==1
replace profileborn = 3 if mexicobornprofile==1
replace profileborn = 4 if philippnesbornprofile==1
replace profileborn = 5 if somaliabornprofile==1
label define Country 1 "USA" 2 "Canada" 3 "Mexico" ///
4 "The Philippines" 5 "Somalia"
label values profileborn Country

gen profileedu = 1
replace profileedu = 2 if highschoolprofile==1
replace profileedu = 3 if collegeprofile==1
replace profileedu = 4 if bachelorsprofile==1
replace profileedu = 5 if mastersprofile==1
label define Education 1 "Less than high school" 2 "High school" 3 "College" ///
4 "Bachelor's degree" 5 "Master's degree" 
label values profileedu Education

gen profilegender = 1
replace profilegender = 2 if gendermanprofile==1
label define Gender 1 "Woman" 2 "Man"
label values profilegender Gender
 
gen profiletaxpayer = 1
replace profiletaxpayer = 2 if incometaxyesprofile==1
label define Taxes 1 "Pays no income taxes in the US" ///
2 "Pays income taxes in the US"
label values profiletaxpayer Taxes

gen profileresidence = 1
replace profileresidence = 2 if us3profile==1
replace profileresidence = 3 if ustouristprofile==1
replace profileresidence = 4 if europe3profile==1
replace profileresidence = 5 if europe15profile==1
label define Residence 1 "Lived in the US the last 15 years" ///
2 "Lived in the US the last 3 years" 3 "Tourist in the US" ///
4 "Lived in Europe the last 3 years" 5 "Lived in Europe the last 15 years"
label values profileresidence Residence
